﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace Fulcrum.ViewModelGenerator.UnitTests
{
    #region ViewModelCollectionXmlConfiguration

    [TestClass]
    public class ViewModelXmlCollectionConfigurationTests
    {
        #region Helpers

        XDocument MinCollectionXml { get; set; }
        IViewModelCollectionConfig MinCollection { get; set; }

        [TestInitialize]
        public void Init()
        {
            this.MinCollectionXml = XmlHelper.CreateMinimalViewModelCollection();
            this.MinCollection = new ViewModelCollectionXmlConfig(this.MinCollectionXml);
        }

        #endregion Helpers

        #region Ctor

        [TestMethod]
        public void ViewModelXmlCollectionConfiguration_Ctor_NullXmlArgument()
        {
            try
            {
                new ViewModelCollectionXmlConfig(null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlCollectionConfiguration_ViewModels_NoElement()
        {
            try
            {
                new ViewModelCollectionXmlConfig(new XDocument());
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        #endregion Ctor

        #region Attributes

        [TestMethod]
        public void ViewModelXmlCollectionConfiguration_CompanyAttribute_Required()
        {
            var doc = new XDocument(new XElement("ViewModels"));

            try
            {
                new ViewModelCollectionXmlConfig(doc);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("Company", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlCollectionConfiguration_CopyrightAttribute_Required()
        {
            var doc = new XDocument(new XElement("ViewModels",
                                        new XAttribute("Company", "Company")));

            try
            {
                new ViewModelCollectionXmlConfig(doc);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("Copyright", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlCollectionConfiguration_NamespaceAttribute_Default()
        {
            Assert.AreEqual<string>(String.Empty, this.MinCollection.Namespace);
        }

        [TestMethod]
        public void ViewModelXmlCollectionConfiguration_NamespaceAttribute_Explicit()
        {
            var xml = this.MinCollectionXml;
            xml.Element("ViewModels").Add(new XAttribute("Namespace", "Namespace"));

            var collection = new ViewModelCollectionXmlConfig(xml);

            Assert.AreEqual<string>("Namespace", collection.Namespace);
        }

        #endregion Attributes

        #region ViewModels

        [TestMethod]
        public void ViewModelXmlCollectionConfiguration_ViewModels_AddVariableNumber()
        {
            var viewModels = StringGenerator.GetNames(100);
            var collection = new ViewModelCollectionXmlConfig(XmlHelper.CreateViewModelCollection(viewModels));

            CollectionAssert.AreEqual(viewModels, collection.ViewModels.Select(vm => vm.Name).ToList());
        }

        #endregion ViewModels
    }

    #endregion ViewModelCollectionXmlConfiguration

    #region ViewModelXmlConfiguration

    [TestClass]
    public class ViewModelXmlConfigurationTests
    {
        #region Helpers

        XElement MinViewModelXml { get; set; }
        IViewModelConfiguration MinViewModel { get; set; }

        [TestInitialize]
        public void Init()
        {
            this.MinViewModelXml = XmlHelper.CreateMinimalViewModel("Boo");
            this.MinViewModel = new ViewModelXmlConfiguration(this.MinViewModelXml);
        }

        #endregion Helpers

        #region Ctor

        [TestMethod]
        public void ViewModelXmlConfiguration_Ctor_NullXmlArgument()
        {
            try
            {
                new ViewModelXmlConfiguration(null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_Ctor_InvalidXmlElementArgument()
        {
            try
            {
                new ViewModelXmlConfiguration(new XElement("InvalidElement"));
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_Ctor_EmptyXmlElementArgument()
        {
            try
            {
                new ViewModelXmlConfiguration(new XElement("ViewModel"));
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_Ctor_NullDefaultNamespace()
        {
            var xml = new XElement("ViewModel",
                new XAttribute("A", String.Empty));

            try
            {
                new ViewModelXmlConfiguration(xml, null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("defaultNamespace", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        #endregion Ctor

        #region Attributes

        [TestMethod]
        public void ViewModelXmlConfiguration_NameAttribute_Required()
        {
            var xml = new XElement("ViewModel",
                new XAttribute("A", String.Empty));

            try
            {
                new ViewModelXmlConfiguration(xml);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("Name", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_NamespaceAttribute_ImplicitDefault()
        {
            Assert.AreEqual<string>(String.Empty, this.MinViewModel.Namespace);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_NamespaceAttribute_ExplicitDefault()
        {
            string explicitDefaultNamespace = "ExplicitDefaultNamespace";
            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml, explicitDefaultNamespace);

            Assert.AreEqual<string>(explicitDefaultNamespace, vm.Namespace);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_NamespaceAttribute_ExplicitNamespaceOverridesDefault()
        {
            string explicitNamespace = "ExplicitNamespace";
            this.MinViewModelXml.Add(new XAttribute("Namespace", "ExplicitNamespace"));

            string explicitDefaultNamespace = "ExplicitDefaultNamespace";
            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml, explicitDefaultNamespace);

            Assert.AreEqual<string>(explicitNamespace, vm.Namespace);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_LocationAttribute_Default()
        {
            Assert.AreEqual<string>(String.Empty, this.MinViewModel.Location);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_LocationAttribute_Explicit()
        {
            string location = "location";
            this.MinViewModelXml.Add(new XAttribute("Location", location));

            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml);

            Assert.AreEqual<string>(location, vm.Location);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_ProvidePropertyChangedEventAttribute_Default()
        {
            Assert.AreEqual(true, this.MinViewModel.ProvidePropertyChangedEvent);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_ProvidePropertyChangedEventAttribute_Explicit()
        {
            this.MinViewModelXml.Add(new XAttribute("ProvidePropertyChangedEvent", false));

            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml);

            Assert.AreEqual(false, vm.ProvidePropertyChangedEvent);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_SummaryAttribute_Default()
        {
            var xml = new XElement("ViewModel",
                new XAttribute("Name", "Class Name"),
                new XAttribute("Location", "location"));

            var vm = new ViewModelXmlConfiguration(xml);

            Assert.AreEqual(String.Empty, vm.Summary);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_SummaryAttribute_Explicit()
        {
            Assert.AreEqual<string>("Summary", this.MinViewModel.Summary);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_RemarksAttribute_Default()
        {
            Assert.AreEqual<string>(String.Empty, this.MinViewModel.Remarks);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_RemarksAttribute_Explicit()
        {
            string remarks = "remarks";
            this.MinViewModelXml.Add(new XAttribute("Remarks", remarks));

            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml);

            Assert.AreEqual<string>(remarks, vm.Remarks);
        }

        #endregion Attributes

        #region Usings

        List<string> defaultUsings = new List<string>()
            {
                "System",
                "System.ComponentModel"
            };

        [TestMethod]
        public void ViewModelXmlConfiguration_Usings_Default()
        {
            Assert.AreEqual<int>(this.defaultUsings.Count, this.MinViewModel.Usings.Count);

            bool match = this.MinViewModel.Usings.ToList().TrueForAll(u => this.defaultUsings.Contains(u));
            Assert.IsTrue(match);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_Usings_AddDefault()
        {
            defaultUsings.ForEach(u => this.MinViewModelXml.Add(new XElement("Using", u)));

            Assert.AreEqual<int>(this.defaultUsings.Count, this.MinViewModel.Usings.Count);

            bool match = this.MinViewModel.Usings.ToList().TrueForAll(u => this.defaultUsings.Contains(u));
            Assert.IsTrue(match);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_Usings_VariableNumberOfUsings()
        {
            var usings = new List<string>()
            {
                "F",
                "E",
                "D",
                "C",
                "B",
                "A"
            }.Take(new Random().Next(5)).ToList();
            usings.ForEach(u => this.MinViewModelXml.Add(new XElement("Using", u)));

            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml);

            var expectedUsings = this.defaultUsings.Concat(usings).ToList();
            expectedUsings.Sort();

            CollectionAssert.AreEqual(expectedUsings, vm.Usings.ToList());
        }

        #endregion Usings

        #region Properties

        [TestMethod]
        public void ViewModelXmlConfiguration_Properties_NoneByDefault()
        {
            Assert.AreEqual<int>(0, this.MinViewModel.Properties.Count);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_Properties_AddVariableNumber()
        {
            var properties = new List<string>()
            {
                "F",
                "E",
                "D",
                "C",
                "B",
                "A"
            }.Take(new Random().Next(5)).ToList();

            properties.ForEach(p => this.MinViewModelXml.Add(XmlHelper.CreateMinimalViewModelProperty(p)));
            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml);

            var expectedProperties = new List<string>(properties);
            expectedProperties.Sort();

            CollectionAssert.AreEqual(expectedProperties, vm.Properties.Select(p => p.Name).ToList());

            var expectedEvents = from p in expectedProperties
                                 select String.Format("{0}Changed", p);

            CollectionAssert.AreEqual(expectedEvents.ToList(), vm.Events.Select(e => e.Name).ToList());
        }

        #endregion Properties

        #region Events

        [TestMethod]
        public void ViewModelXmlConfiguration_Events_NoneByDefault()
        {
            Assert.AreEqual<int>(0, this.MinViewModel.Properties.Count);
        }

        [TestMethod]
        public void ViewModelXmlConfiguration_Events_AddVariableNumber()
        {
            var events = new List<string>()
            {
                "F",
                "E",
                "D",
                "C",
                "B",
                "A"
            }.Take(new Random().Next(6)).ToList();

            events.ForEach(p => this.MinViewModelXml.Add(XmlHelper.CreateMinimalViewModelEvent(p)));
            var vm = new ViewModelXmlConfiguration(this.MinViewModelXml);

            var expectedEvents = new List<string>(events);
            expectedEvents.Sort();

            CollectionAssert.AreEqual(expectedEvents, vm.Events.Select(e => e.Name).ToList());
        }

        #endregion Events
    }

    #endregion ViewModelXmlConfiguration

    #region ViewModelXmlProperty

    [TestClass]
    public class ViewModelXmlPropertyTests
    {
        #region Helpers

        XElement MinPropertyXml { get; set; }
        IViewModelPropertyConfiguration MinProperty { get; set; }

        [TestInitialize]
        public void Init()
        {
            this.MinPropertyXml = XmlHelper.CreateMinimalViewModelProperty("Boo");
            this.MinProperty = new ViewModelPropertyXmlConfiguration(this.MinPropertyXml);
        }

        IViewModelPropertyConfiguration CreateProperty(XElement xml)
        {
            return new ViewModelPropertyXmlConfiguration(xml);
        }

        IViewModelPropertyConfiguration CreatePropertyWithAttributes(params string[] attributesToAdd)
        {
            var xml = new XElement("Property");

            if (null != attributesToAdd)
            {
                attributesToAdd.ToList().ForEach(o => xml.Add(new XAttribute(o, o)));
            }

            return new ViewModelPropertyXmlConfiguration(xml);
        }

        #endregion Helpers

        #region Ctor

        [TestMethod]
        public void ViewModelXmlProperty_Ctor_NullXmlArgument()
        {
            try
            {
                this.CreateProperty(null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlProperty_Ctor_InvalidElementArgument()
        {
            try
            {
                this.CreateProperty(new XElement("NotAProperty"));
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        #endregion Ctor

        #region Attributes

        [TestMethod]
        public void ViewModelXmlProperty_NameAttribute_Required()
        {
            try
            {
                this.CreatePropertyWithAttributes();
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("Name", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlProperty_Name_LowerCaseName()
        {
            try
            {
                this.CreateProperty(XmlHelper.CreateMinimalViewModelProperty("name"));
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("Name", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlProperty_TypeAttribute_Required()
        {
            try
            {
                this.CreatePropertyWithAttributes("Name");
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("Type", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlProperty_DefaultValueAttribute_Required()
        {
            try
            {
                this.CreatePropertyWithAttributes("Name", "Type");
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("DefaultValue", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlProperty_ValidateValueAttribute_Default()
        {
            Assert.AreEqual<bool>(false, this.MinProperty.IsValidated);
        }

        [TestMethod]
        public void ViewModelXmlProperty_ValidateValueAttribute_Explicit()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("ValidateValue", true));

            var property = this.CreateProperty(xml);
            Assert.AreEqual<bool>(true, property.IsValidated);
        }

        [TestMethod]
        public void ViewModelXmlProperty_IsSerializedAttribute_Default()
        {
            Assert.AreEqual<bool>(true, this.MinProperty.IsSerializable);
        }

        [TestMethod]
        public void ViewModelXmlProperty_IsSerializedAttribute_Explicit()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("Serializable", false));

            var property = this.CreateProperty(xml);
            Assert.AreEqual<bool>(false, property.IsSerializable);
        }

        [TestMethod]
        public void ViewModelXmlProperty_SetterVisibilityAttribute_Default()
        {
            Assert.AreEqual(PropertyVisibility.Public, this.MinProperty.SetPropertyVisibility);
        }

        [TestMethod]
        public void ViewModelXmlProperty_SetterVisibilityAttribute_Explicit_Public()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("SetterVisibility", "public"));

            var property = this.CreateProperty(xml);
            Assert.AreEqual(PropertyVisibility.Public, property.SetPropertyVisibility);
        }

        [TestMethod]
        public void ViewModelXmlProperty_SetterVisibilityAttribute_Explicit_Protected()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("SetterVisibility", "Protected"));

            var property = this.CreateProperty(xml);
            Assert.AreEqual(PropertyVisibility.Protected, property.SetPropertyVisibility);
        }

        [TestMethod]
        public void ViewModelXmlProperty_SetterVisibilityAttribute_Explicit_Private()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("SetterVisibility", "private"));

            var property = this.CreateProperty(xml);
            Assert.AreEqual(PropertyVisibility.Private, property.SetPropertyVisibility);
        }

        [TestMethod]
        public void ViewModelXmlProperty_ComparisonAttribute_Default()
        {
            Assert.AreEqual(PropertyComparison.Equals, this.MinProperty.Comparison);
        }

        [TestMethod]
        public void ViewModelXmlProperty_ComparisonAttribute_Explicit()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("Comparison", "Custom"));

            var property = this.CreateProperty(xml);
            Assert.AreEqual(PropertyComparison.Custom, property.Comparison);
        }

        [TestMethod]
        public void ViewModelXmlProperty_StringComparisonAttribute_Default()
        {
            Assert.AreEqual(StringComparison.Ordinal, this.MinProperty.StringComparison);
        }

        [TestMethod]
        public void ViewModelXmlProperty_StringComparisonyAttribute_Explicit()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("StringComparison", "CurrentCultureIgnoreCase"));

            var property = this.CreateProperty(xml);
            Assert.AreEqual(StringComparison.CurrentCultureIgnoreCase, property.StringComparison);
        }

        [TestMethod]
        public void ViewModelXmlProperty_SummaryAttribute_Required()
        {
            try
            {
                this.CreatePropertyWithAttributes("Name", "Type", "DefaultValue");
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("Summary", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelXmlProperty_RemarksAttribute_Default()
        {
            Assert.AreEqual<string>(String.Empty, this.MinProperty.Remarks);
        }

        [TestMethod]
        public void ViewModelXmlProperty_RemarksAttribute_Explicit()
        {
            var xml = this.MinPropertyXml;
            xml.Add(new XAttribute("Remarks", "Remarks"));

            var property = this.CreateProperty(xml);
            Assert.AreEqual<string>("Remarks", property.Remarks);
        }

        #endregion Attributes

        #region Properties

        [TestMethod]
        public void ViewModelXmlProperty_FieldName()
        {
            string name = "PropertyName";
            var xml = XmlHelper.CreateMinimalViewModelProperty(name);

            var property = this.CreateProperty(xml);

            string fieldName = "_propertyName";
            Assert.AreEqual<string>(fieldName, property.FieldName);
        }

        [TestMethod]
        public void ViewModelXmlProperty_FieldName_LengthOne()
        {
            string name = "P";
            var xml = XmlHelper.CreateMinimalViewModelProperty(name);

            var property = this.CreateProperty(xml);

            string fieldName = "_p";
            Assert.AreEqual<string>(fieldName, property.FieldName);
        }

        #endregion Properties
    }

    #endregion ViewModelXmlProperty

    #region ViewModelEventXmlConfiguration

    [TestClass]
    public class ViewModelEventXmlConfigurationTests
    {
        #region Helpers

        XElement MinEventXml { get; set; }
        IViewModelEventConfiguration MinEvent { get; set; }

        [TestInitialize]
        public void Init()
        {
            this.MinEventXml = XmlHelper.CreateMinimalViewModelEvent("Event");
            this.MinEvent = this.CreateEvent(this.MinEventXml);
        }

        IViewModelEventConfiguration CreateEvent(XElement xml)
        {
            return new ViewModelEventXmlConfiguration(xml);
        }

        IViewModelEventConfiguration CreateEventWithAttributes(params string[] attributesToAdd)
        {
            var xml = new XElement("Event");

            if (null != attributesToAdd)
            {
                attributesToAdd.ToList().ForEach(o => xml.Add(new XAttribute(o, o)));
            }

            return this.CreateEvent(xml);
        }

        #endregion Helpers

        #region Ctor

        [TestMethod]
        public void ViewModelEventXmlConfiguration_Ctor_NullNameArgument()
        {
            try
            {
                new ViewModelEventXmlConfiguration(null, null, null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("name", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_Ctor_EmptyArgument()
        {
            try
            {
                new ViewModelEventXmlConfiguration("  ", null, null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("name", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_Ctor_NullEventArgsTypeArgument()
        {
            try
            {
                new ViewModelEventXmlConfiguration("Name", null, null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("eventArgsType", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_Ctor_NullSummaryArgument()
        {
            try
            {
                new ViewModelEventXmlConfiguration("Name", "Type", null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("summary", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_Ctor_NullXmlArgument()
        {
            try
            {
                new ViewModelEventXmlConfiguration(null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_Ctor_InvalidXmlElementArgument()
        {
            try
            {
                new ViewModelEventXmlConfiguration(new XElement("NotEvent"));
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual<string>("xml", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        #endregion Ctor

        #region Attributes

        [TestMethod]
        public void ViewModelEventXmlConfiguration_NameAttribute_Required()
        {
            try
            {
                this.CreateEventWithAttributes();
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("Name", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_EventArgsTypeAttribute_Required()
        {
            try
            {
                this.CreateEventWithAttributes("Name");
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("EventArgsType", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_TypeAttribute_Default()
        {
            Assert.AreEqual<string>("EventHandler<EventArgsType>", this.MinEvent.Type);
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_TypeAttribute_DefaultIfEventArgs()
        {
            this.MinEventXml.Attribute("EventArgsType").Value = "EventArgs";
            var @event = this.CreateEvent(this.MinEventXml);

            Assert.AreEqual<string>("EventHandler", @event.Type);
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_TypeAttribute_Explicit()
        {
            this.MinEventXml.Add(new XAttribute("Type", "MyEventHandler"));
            var @event = this.CreateEvent(this.MinEventXml);

            Assert.AreEqual<string>("MyEventHandler", @event.Type);
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_SummaryAttribute_Required()
        {
            try
            {
                this.CreateEventWithAttributes("Name", "EventArgsType");
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>("Summary", e.ParamName);
                return;
            }

            Assert.Fail();
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_RemarksAttribute_Default()
        {
            Assert.AreEqual<string>(String.Empty, this.MinEvent.Remarks);
        }

        [TestMethod]
        public void ViewModelEventXmlConfiguration_RemarksAttribute_Explicit()
        {
            var xml = this.MinEventXml;
            xml.Add(new XAttribute("Remarks", "Remarks"));

            var property = this.CreateEvent(xml);
            Assert.AreEqual<string>("Remarks", property.Remarks);
        }

        #endregion Attributes
    }

    #endregion ViewModelEventXmlConfiguration

}
